import { deptTypeEnum, stateEnum, typeEnum } from '@/enum';
import { getViewApply } from '@/services/ant-design-pro/apply';
import { getKnowledFile } from '@/services/ant-design-pro/corpus';
import {
  CheckCircleFilled,
  ClockCircleFilled,
  CloseCircleFilled,
  MinusCircleFilled,
} from '@ant-design/icons';
import { ProColumns, ProTable } from '@ant-design/pro-components';
import hooks from '../../hooks/useHooks';
import ApplyAuthKnowledge from '@/pages/AuthKnowledge/ApplyAuthKnowledge';
const ApplyKnowledge = (props: any) => {
  const { setDetail, setDisabled, setType, setApplyVisible } = hooks.useContainer();

  const columns: ProColumns<any>[] = [
    {
      dataIndex: 'index',
      valueType: 'indexBorder',
      width: 48,
      title: '序号',
    },
    {
      title: '任务名称',

      dataIndex: 'applyName',
      hideInForm: false,
      ellipsis: true,
      search: false,
    },
    {
      title: '申请类型',
      dataIndex: 'type',
      ellipsis: true,
      render: (_, record: any) => [
        <span key={1}>
          <span style={{ marginLeft: '5.0px' }}>{deptTypeEnum[record?.type + '']}</span>
        </span>,
      ],
      width: 100,
    },
    {
      title: '审核状态',
      dataIndex: 'status',
      ellipsis: true,
      search: false,

      render: (_, record: any) => [
        <span key={1}>
          {record?.status === 'REVIEW_APPROVE' ? (
            <ClockCircleFilled style={{ color: 'green' }} />
          ) : record?.status === 'REVIEWING' ? (
            <MinusCircleFilled style={{ color: '#1890ff' }} />
          ) : (
            <CloseCircleFilled style={{ color: 'red' }} />
          )}
          <span style={{ marginLeft: '5.0px' }}>{stateEnum[record?.status + '']}</span>
        </span>,
      ],
    },

    {
      title: '审核部门',
      dataIndex: 'reviewerDeptName',
      ellipsis: true,
    },

    {
      title: '审核时间',
      dataIndex: 'reviewTime',
      ellipsis: true,
      search: false,
    },
    {
      title: '审核意见',
      dataIndex: 'comments',
      ellipsis: true,
    },

    {
      title: '操作',
      width: 100,
      dataIndex: 'option',
      render: (_, record: any) => [
        <a
          key={1}
          onClick={() => {
            setDetail({
              ...record,
              deptCode: record.knowledgeDeptCode,
              deptName: record.knowledgeDeptName,
              name: record.knowledgeName,
            });
            setType(record.type);
            setDisabled(true);
            setApplyVisible(true);
          }}
        >
          查看
        </a>,
      ],
    },
  ];
  return (
    <>
      <ProTable<API.RuleListItem, API.PageParams>
        toolBarRender={() => []}
        rowKey="key"
        request={async (
          // 第一个参数 params 查询表单和 params 参数的结合
          // 第一个参数中一定会有 pageSize 和  current ，这两个参数是 antd 的规范
          params: any,
        ) => {
          // 这里需要返回一个 Promise,在返回之前你可以进行数据转化
          // 如果需要转化参数可以在这里进行修改

          const msg = await getViewApply({
            ...params,
            viewType: 1,
          });
          return {
            data: msg.data,
            // success 请返回 true，
            // 不然 table 会停止解析数据，即使有数据
            success: true,
            // 不传会使用 data 的长度，如果是分页一定要传
            total: msg.total,
          };
        }}
        search={false}
        pagination={{
          showSizeChanger: true,
          defaultPageSize: 10,
        }}
        options={false}
        columns={columns}
      />
      <ApplyAuthKnowledge />
    </>
  );
};
export default ApplyKnowledge;
